﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PersonalAccounting.Business;

namespace PersonalAccounting.Forms
{
    public partial class FormConsSaldos : Form
    {

        #region Attributes

        private SaldoFacade facade;
        private List<Saldo> resultado;

        #endregion

        #region Form

        public FormConsSaldos()
        {
            facade = new SaldoFacade();
            resultado = null;

            InitializeComponent();
        }

        private void FormConsSaldos_Load(object sender, EventArgs e)
        {
            dtpFecha.Value = DateTime.Today;
        }

        #endregion

                
        #region Click

        private void btnConsultar_Click(object sender, EventArgs e)
        {
            CargarDatos();
            MostrarDatos();
        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        #endregion

        #region ValueChanged

        private void dtpFecha_ValueChanged(object sender, EventArgs e)
        {
            LimpiarForm();
        }

        #endregion

        

        private void LimpiarForm()
        {
            lvSaldos.Items.Clear();
        }

        private void CargarDatos()
        {
            DateTime fecha = dtpFecha.Value;

            resultado = facade.GetSaldos(fecha);
        }

        private void MostrarDatos()
        {
            LimpiarForm();

            foreach (Saldo sdo in resultado)
            {
                ListViewItem item = lvSaldos.Items.Add(sdo.Cuenta.ToString());
                
                item.SubItems.Add(sdo.SaldoCuenta.ToString("###,###,###,###.00"));
                item.Tag = sdo.Cuenta;

                if (item.Index % 2 != 0)
                    item.BackColor = Color.WhiteSmoke;
            }
        }

    }
}